package com.medical.wechat.web.controller;

import com.medical.common.JsonResult;
import com.medical.wechat.model.WechatReplyText;
import com.medical.wechat.service.WechatReplyTextService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;
import java.util.List;
import java.util.UUID;

/**
 * Created by Administrator on 2016/11/1.
 */
@Controller
@RequestMapping("/wechatReplyText")
public class WechatReplyTextController {
    @Autowired
    private WechatReplyTextService wechatReplyTextService;

    //根据accountId查找关注时回复消息
    @ApiOperation(value="根据accountId查找关注时回复消息", notes="根据accountId查找关注时回复消息")
    @RequestMapping(value = "/get/{accountId}",method = RequestMethod.GET)
    @ResponseBody
    public JsonResult selectById(@PathVariable String accountId){
        List<WechatReplyText> wechatReplyText = wechatReplyTextService.findByAccountId(accountId);
        return new JsonResult("200","",wechatReplyText);
    }

    //新增
    @ApiOperation(value="新增", notes="新增")
    @RequestMapping(value = "/post",method = RequestMethod.POST)
    @ResponseBody
    public JsonResult post(@RequestParam("keyword") String keyword,
                           @RequestParam("content") String  content ){
        WechatReplyText wechatReplyText = new WechatReplyText();
        wechatReplyText.setKeyword(keyword);
        wechatReplyText.setContent(content);
        wechatReplyTextService.insert(wechatReplyText);
        return new JsonResult("200","");
    }

    //编辑
    @ApiOperation(value="编辑", notes="编辑")
    @RequestMapping(value = "/patch/{id}",method = RequestMethod.POST)
    @ResponseBody
    public JsonResult patch(@PathVariable String id,
                            @RequestParam(value = "accountId",required = false) String accountId  ,
                            @RequestParam(value = "keyword",required = false) String keyword  ,@RequestParam(value = "createdBy",required = false) String createdBy  ,
                            @RequestParam(value = "content",required = false) String content){
        WechatReplyText wechatReplyText=wechatReplyTextService.findById(id);
        wechatReplyText.setAccountId(accountId);
        wechatReplyText.setKeyword(keyword);
        wechatReplyText.setContent(content);
        wechatReplyText.setCreatedBy(createdBy);
        wechatReplyTextService.updateById(wechatReplyText);
        return new JsonResult("200","",wechatReplyTextService.findById(id));
    }

    //删除
    @ApiOperation(value="删除", notes="删除")
    @RequestMapping(value = "/delete/{id}",method = RequestMethod.POST)
    @ResponseBody
    public JsonResult delete(@PathVariable String id){
        wechatReplyTextService.deleteById(id);
        return new JsonResult();
    }
}
